package chain

import "awesomeProject1/models/pojo"

func (b *Block) Parse() *models.BlockWitchTransactions {
	if b == nil {
		return nil
	}
	var txs []*models.Transaction
	for _, v := range b.Transactions {
		t := &models.Transaction{
			Id:               0,
			TransactionIndex: v.TransactionIndex,
			Hash:             v.Hash,
			BlockNumber:      v.BlockNumber,
			BlockHash:        v.BlockHash,
			From:             v.From,
			Recipient:        v.Recipient,
			Amount:           v.Amount,
			AccountNonce:     v.AccountNonce,
			Price:            v.Price,
			GasLimit:         v.GasLimit,
			Payload:          v.Payload,
			V:                v.V,
			R:                v.R,
			S:                v.S,
		}
		txs = append(txs, t)
	}
	return &models.BlockWitchTransactions{
		Block: models.Block{
			Id:              0,
			Number:          b.Number,
			Hash:            b.Hash,
			ParentHash:      b.ParentHash,
			Nonce:           b.Nonce,
			TxHash:          b.TxHash,
			Coinbase:        b.Coinbase,
			Root:            b.Root,
			Bloom:           b.Bloom,
			Difficulty:      b.Difficulty,
			GasLimit:        b.GasLimit,
			GasUsed:         b.GasUsed,
			ReceiptHash:     b.ReceiptHash,
			Time:            b.Time,
			Extra:           b.Extra,
			UncleHash:       b.UncleHash,
			MixDigest:       b.MixDigest,
			TotalDifficulty: b.TotalDifficulty,
			Size:            b.Size,
			TxNu:            len(b.Transactions),
		},
		Transactions: txs,
	}
}
func (v *Transaction) Parse() *models.Transaction {
	if v == nil {
		return nil
	}
	return &models.Transaction{
		Id:               0,
		TransactionIndex: v.TransactionIndex,
		Hash:             v.Hash,
		BlockNumber:      v.BlockNumber,
		BlockHash:        v.BlockHash,
		From:             v.From,
		Recipient:        v.Recipient,
		Amount:           v.Amount,
		AccountNonce:     v.AccountNonce,
		Price:            v.Price,
		GasLimit:         v.GasLimit,
		Payload:          v.Payload,
		V:                v.V,
		R:                v.R,
		S:                v.S,
	}
}
